<template>
  <div class="app-container">
      <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
    >
      <el-form-item label="用户总积分最大值" prop="totalScoreMax">
        <el-input
          v-model="queryParams.totalScoreMax"
          placeholder="用户总积分最大值"
          clearable
          style="width: 200px"
        />
      </el-form-item>

       <el-form-item label="用户总积分最小值" prop="totalScoreMin">
        <el-input
          v-model="queryParams.totalScoreMin"
          placeholder="用户总积分最小值"
          clearable
          style="width: 200px"
        />
      </el-form-item>


      <el-form-item>
         <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格数据 -->
    <el-table
      v-loading="loading"
      :data="roleList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="角色编号" prop="id" width="120" />
      <el-table-column
        label="角色名称"
        prop="name"
        :show-overflow-tooltip="true"
        width="150"
      />
      <el-table-column
        label="权限字符"
        prop="roleKey"
        :show-overflow-tooltip="true"
        width="150"
      />
      <el-table-column label="显示顺序" prop="sort" width="100" />
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-tooltip
            content="修改"
            placement="top"
            v-if="scope.row.isAdmin !== 1"
          >
            <el-button
              link
              type="primary"
              icon="Edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['admin:role:update']"
            ></el-button>
          </el-tooltip>
          <el-tooltip
            content="删除"
            placement="top"
            v-if="scope.row.isAdmin !== 1"
          >
            <el-button
              link
              type="primary"
              icon="Delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['admin:user:remove']"
            ></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.page"
      v-model:limit="queryParams.size"
      @pagination="getList"/>
  </div>
</template>

<script setup name="Role">
import { listRole} from "@/api/min-app/permission";
const { proxy } = getCurrentInstance();

const roleList = ref([]);
const loading = ref(true);
const total = ref(0);
const dateRange = ref([]);

const data = reactive({
  form: {},
  queryParams: {
    page: 1,
    size: 10,
    totalScoreMin: undefined,
    totalScoreMax: undefined,
  },
});

const { queryParams, form, rules } = toRefs(data);

/** 查询角色列表 */
function getList() {
  loading.value = true;

const params = {
  page: queryParams.value.page,
  size: queryParams.value.size,
  totalScoreMin: queryParams.value.totalScoreMin || "",
  totalScoreMax: queryParams.value.totalScoreMax || ""
}

listRole(params).then(res => {
  roleList.value = res.data.records
  total.value = Number(res.data.total)   // 保证是数字
  loading.value = false
})


}

// 搜索
function handleQuery() {
  queryParams.value.page = 1;
  getList();
}

// 重置
function resetQuery() {
  queryParams.value.page = 1;
  queryParams.value.userId = '';
  queryParams.value.agentId = '';
  getList();
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.roleId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}
getList();
</script>
